﻿using DLL.Standard.Infrastructure;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DLL.NET60.DB.MS.Entity.DTO
{
    [Serializable]
    public partial class DTO_adi_dic_drug : CNotifyPropertyChanged, ICloneable
    {
        //private int _ID = 0;
        private DateTime _updateTime = DateTime.Now;

        private string _Drug_UniqueCode = "";
        private string _DRUG_NAME = "";
        private string _PY_CODE = "";
        private string _SPECIFICATION = "";
        private float _DOSE = 0;
        private string _DOSE_UNIT = "";
        private string _MAFC_NAME = "药品厂家";
        private string _DRUG_CODE = "";
        private string _ApprovalNumber = "";
        private decimal? _SOLVENT_FLAG;
        private decimal? _NEEDLE_TYPE = 0;
        private int _BOTTLE_TYPE = 0;
        private float _BOTTLE_SIZE = 0;
        private float _BOTTLE_VOLUME = 0;
        private float _BOTTLE_THICKNESS = 0;//瓶塞厚度
        private int _SOLUBILITY = 3;
        private int _POSITIVE_PRESSURE = 3;
        private int _HAS_BUBBLE = 0;
        private int _Viscosity = 0;
        private int _FLUSH_MODE = 0;

        private int _FlushGroupIndex = 0;

        private int _ORIGINAL_PRESSURE = 3;
        private float _OrgPullOutAire = 0;
        private float _InjcetBackDistance = 1;
        private int _InjcetBackSpeed = 50;

        private int _OpenJawMode = 0;
        private int _DropCrumb = 0;
        private int _PunctureSlowSpeed = 10;
        private int _OutSolventSpeed = 80;//抽溶媒速度
        private float _CoefficientOfExpansion = 0;//膨胀系数

        [StringLength(255)]
        public DateTime updateTime
        { get { return _updateTime; } set { _updateTime = value; OnPropertyChanged(); } }

        public string Drug_UniqueCode
        { get { return _Drug_UniqueCode; } set { _Drug_UniqueCode = value; this.OnPropertyChanged(); } }

        //[Key]
        [StringLength(255)]
        public string DRUG_CODE
        { get { return _DRUG_CODE; } set { _DRUG_CODE = value; this.OnPropertyChanged(); } }

        public string DRUG_NAME
        { get { return _DRUG_NAME; } set { _DRUG_NAME = value; this.OnPropertyChanged(); } }

        public string SPECIFICATION
        { get { return _SPECIFICATION; } set { _SPECIFICATION = value; this.OnPropertyChanged(); } }

        public float DOSE
        { get { return _DOSE; } set { _DOSE = value; this.OnPropertyChanged(); } }

        public string DOSE_UNIT
        { get { return _DOSE_UNIT; } set { _DOSE_UNIT = value; this.OnPropertyChanged(); } }

        public string MAFC_NAME
        { get { return _MAFC_NAME; } set { _MAFC_NAME = value; this.OnPropertyChanged(); } }

        public decimal? SOLVENT_FLAG
        { get { return _SOLVENT_FLAG; } set { _SOLVENT_FLAG = value; this.OnPropertyChanged(); } }

        public string PY_CODE
        { get { return _PY_CODE; } set { _PY_CODE = value; this.OnPropertyChanged(); } }

        public string ApprovalNumber
        { get { return _ApprovalNumber; } set { _ApprovalNumber = value; this.OnPropertyChanged(); } }

        public float BOTTLE_SIZE
        { get { return _BOTTLE_SIZE; } set { _BOTTLE_SIZE = value; this.OnPropertyChanged(); } }

        public float BOTTLE_VOLUME
        { get { return _BOTTLE_VOLUME; } set { _BOTTLE_VOLUME = value; this.OnPropertyChanged(); } }

        public float BOTTLE_THICKNESS
        { get { return _BOTTLE_THICKNESS; } set { _BOTTLE_THICKNESS = value; this.OnPropertyChanged(); } }

        public int BOTTLE_TYPE
        { get { return _BOTTLE_TYPE; } set { _BOTTLE_TYPE = value; this.OnPropertyChanged(); } }

        public decimal? NEEDLE_TYPE
        { get { return _NEEDLE_TYPE; } set { _NEEDLE_TYPE = value; this.OnPropertyChanged(); } }

        public int SOLUBILITY
        { get { return _SOLUBILITY; } set { _SOLUBILITY = value; this.OnPropertyChanged(); } }

        public int ORIGINAL_PRESSURE
        { get { return _ORIGINAL_PRESSURE; } set { _ORIGINAL_PRESSURE = value; this.OnPropertyChanged(); } }

        public int POSITIVE_PRESSURE
        { get { return _POSITIVE_PRESSURE; } set { _POSITIVE_PRESSURE = value; this.OnPropertyChanged(); } }

        public int HAS_BUBBLE
        { get { return _HAS_BUBBLE; } set { _HAS_BUBBLE = value; this.OnPropertyChanged(); } }

        public int Viscosity
        { get { return _Viscosity; } set { _Viscosity = value; this.OnPropertyChanged(); } }

        public int FLUSH_MODE
        { get { return _FLUSH_MODE; } set { _FLUSH_MODE = value; this.OnPropertyChanged(); } }

        public int OpenJawMode
        { get { return _OpenJawMode; } set { _OpenJawMode = value; this.OnPropertyChanged(); } }

        public int FlushGroupIndex
        { get { return _FlushGroupIndex; } set { _FlushGroupIndex = value; this.OnPropertyChanged(); } }

        public int OutSolventSpeed
        { get { return _OutSolventSpeed; } set { _OutSolventSpeed = value; this.OnPropertyChanged(); } }

        public float OrgPullOutAire
        { get { return _OrgPullOutAire; } set { _OrgPullOutAire = value; this.OnPropertyChanged(); } }

        //InjcetBackDistance
        public float InjcetBackDistance
        { get { return _InjcetBackDistance; } set { _InjcetBackDistance = value; this.OnPropertyChanged(); } }

        public int InjcetBackSpeed
        { get { return _InjcetBackSpeed; } set { _InjcetBackSpeed = value; this.OnPropertyChanged(); } }

        public int DropCrumb
        { get { return _DropCrumb; } set { _DropCrumb = value; this.OnPropertyChanged(); } }

        public int PunctureSlowSpeed
        { get { return _PunctureSlowSpeed; } set { _PunctureSlowSpeed = value; this.OnPropertyChanged(); } }

        public float CoefficientOfExpansion
        { get { return _CoefficientOfExpansion; } set { _CoefficientOfExpansion = value; this.OnPropertyChanged(); } }
        private List<DTO_adi_FlushGroup> _flush_Groups = new List<DTO_adi_FlushGroup>();

        public virtual List<DTO_adi_FlushGroup> flush_Groups
        {
            get { return _flush_Groups; }
            set { _flush_Groups = value; this.OnPropertyChanged(); }
        }

        public void InitializeFlushParam()
        {
            InitializeFlushGroup();
            //flush_Params.Clear();
            //for (int i = 0; i < 10; i++)
            //{
            //    adi_FlushParam fp = new adi_FlushParam();
            //    fp.LoopIndex = i;
            //    fp.Drug_UniqueCode = Drug_UniqueCode;
            //    fp.Flush_UniqueCode = Drug_UniqueCode + "-" + i.ToString();
            //    flush_Params.Add(fp);
            //}
            //pumpBack_Params.Clear();
            //for (int i = 0; i < 5; i++)
            //{
            //    adi_PumpBackParam pbp = new adi_PumpBackParam();
            //    pbp.LoopIndex = i;
            //    pbp.Drug_UniqueCode = Drug_UniqueCode;
            //    pbp.PumpBack_UniqueCode = Drug_UniqueCode + "-" + i.ToString();
            //    pumpBack_Params.Add(pbp);
            //}
        }

        public void InitializeFlushGroup()
        {
            flush_Groups.Clear();
            for (int i = 0; i < 4; i++)
            {
                DTO_adi_FlushGroup fp = new DTO_adi_FlushGroup();
                fp.FlushGroupID = i;
                fp.Drug_UniqueCode = Drug_UniqueCode;
                fp.DrugFlushGroupCode = Drug_UniqueCode + "-" + i.ToString();
                fp.InitializeFlushParam();
                flush_Groups.Add(fp);
            }
        }

        public string GetUniqueCode()
        {
            return DRUG_NAME + "-" + MAFC_NAME + "-" + DOSE.ToString("G");
        }

        public void SetFlushParamUniqueCode()
        {
            Drug_UniqueCode = GetUniqueCode();

            if (flush_Groups.Count > 0)
            {
                int count = flush_Groups.Count;
                for (int i = 0; i < count; i++)
                {
                    flush_Groups[i].Drug_UniqueCode = Drug_UniqueCode;
                    string flushUniqueCode = Drug_UniqueCode + "-" + flush_Groups[i].FlushGroupID.ToString();
                    flush_Groups[i].DrugFlushGroupCode = flushUniqueCode;
                    flush_Groups[i].SetFlushParamUniqueCode(flushUniqueCode);
                }
            }
        }

        public object Clone()
        {
            //浅复制，只可以复制值类型的变量，对医用类型的变量没用
            DTO_adi_dic_drug drug = new DTO_adi_dic_drug();
            drug = Copy(this);
            int count = this.flush_Groups.Count();
            for (int i = 0; i < count; i++)
            {
                drug.flush_Groups.Add((DTO_adi_FlushGroup)this.flush_Groups[i].Clone());
            }
            return drug;
        }

        private DTO_adi_dic_drug Copy(DTO_adi_dic_drug m)
        {
            var model = new DTO_adi_dic_drug();
            var ps = model.GetType().GetProperties();
            var properties = m.GetType().GetProperties();
            foreach (var p in properties)
            {
                foreach (var pm in ps)
                {
                    if (pm.Name == p.Name)
                    {
                        if (pm.Name != "flush_Groups")
                        {
                            pm.SetValue(model, p.GetValue(m));
                        }
                        else
                        {
                            int b = 0;
                        }
                    }
                }
            }
            return model;
        }
    }
}